
// A3_crosswalk_pc8plus
//==============================================================================

// Description: This code crosswalks the data to time-consistent pc8plus categories

clear

cd "D:\data_replication"

use data\number_firms\companies_pc8.dta, clear


// Match PC8 to PC8plus using BBV
//------------------------------------------------------------------------------

merge m:1 prccode year using estimation\1_data_format\crosswalk_pc8_pc8plus_2003_2007_temp.dta
gen match = 3
replace match = 1 if _merge == 1
drop if _merge == 2    															// products in crosswalk but not in dataset
drop _merge
gen pc8plus_temp = pc8plus
drop pc8plus


// Match remaining PC8 via Manual Match 1
//------------------------------------------------------------------------------

merge m:1 prccode year using estimation\1_data_format\manually_matched_pc8_over_time.dta
drop if _merge == 2
tab prccode if _merge == 1 & match == 1
replace pc8plus_temp = pc8plus if _merge == 3
drop _merge pc8plus


// Match remaining PC8 via Manual Match 2
//------------------------------------------------------------------------------

merge m:1 prccode year using estimation\1_data_format\manually_matched_pc8_over_time_2.dta
replace pc8plus_temp = pc8plus if _merge == 3
drop exit synthetic match _merge pc8plus
rename pc8plus_temp pc8plus

drop if pc8plus == ""


// Sum up companies and save
//==============================================================================

sort declarant pc8plus
by declarant pc8plus: egen companies_pc8plus = sum(companies_pc8)
by declarant pc8plus: keep if _n == 1

keep declarant pc8plus companies_pc8plus
save data\number_firms\companies_pc8plus.dta, replace


